1205. Power of Cryptography

 

Given an integer n ³ 1 and an integer p ³ 1 you are to write a program that determines , the positive n - th root of p. There always exists such integer k that kn = p.

 

Input. Consists of two numbers n and p (1 £ n £ 300, 1 £ p < 10101). It is known that there always exists an integer k (1 ≤ k ≤ 109) such that kn = p.

 

Output. Print the value , i.e. the number k such that kn = p.

 

Sample input

7 4357186184021382204544

 

Sample output

1234

 

 

SOLUTION

mathematics

 

Algorithm analysis

It is known that  =  =  = . Subject to the constraints on numbers n, p and k just use double type for their declaration and calculate the value of . In C language it will be written  as exp(log(p)/n).

 

Example

For the given test we have  = 1234.

 

Algorithm realization

Read the values of n and p, calculate and print .

 

scanf("%lf %lf",&n,&p);

res = exp(log(p)/n);

printf("%.0lf\n",res);

 

Java realization

 

import java.util.Scanner;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    double n = con.nextDouble();

    double p = con.nextDouble();

    double res = Math.pow(p,1/n);

    System.out.println((int)(res+0.5));

  }

}